//
//  ByApiStore.m
//  chequanbao_ios
//
//  Created by pro on 2017/7/3.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByApiStore.h"

@implementation ByApiStore

// 获得商城列表
+ (void)getStoreList:(ByNetParamsModel *)model
             success:(void(^)(ByNetBaseResult *result))success
             failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"By_Mall_queryList";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeArray
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** %@ 获取商城列表: %@", apiType, error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];

}
// 获得商城首页
+ (void)getStoreHomeIndex:(ByNetParamsModel *)model
                  success:(void(^)(ByNetBaseResult *result))success
                  failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"By_Product_indexProduct";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** %@ 获取商城首页: %@", apiType, error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}
// 获得商城列表
+ (void)jk_getStoreList:(ByNetParamsModel *)model
                success:(void(^)(ByNetBaseResult *result))success
                failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"By_Product_search";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.type forKey:@"product_type"];
    if (model.page_index) {
        [params setObject:model.page_index forKey:@"page_index"];
    }
    if (model.page_size) {
        [params setObject:model.page_size forKey:@"page_size"];
    }
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** %@ 获取商城首页: %@", apiType, error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}
@end
